<template>
  <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="dialogFormVisible" width="80%" @close="close"
    :append-to-body="true">
    <el-form ref="form" :model="form" :rules="rules" label-width="0.8rem">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item label="库房名称">
            <el-select v-model="form.kufangid" placeholder="请选择">
              <el-option v-for="(item, index) in KufangList" :key="index" :label="item.mingcheng"
                :value="item.id"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="设备编号">
            <el-input v-model.trim="form.shebeibh" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="设备名称">
            <el-input v-model.trim="form.shebeimc" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="设备类别">
            <el-input v-model.trim="form.shebeilb" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="规格型号">
            <el-input v-model.trim="form.guigexh" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="数量">
            <el-input v-model.trim="form.sl" type="number" min="0" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="计量单位">
            <el-input v-model.trim="form.jiliangdw" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="出厂日期">
            <el-date-picker v-model.trim="form.chuchangrq" size="small" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
              :editable="false" placeholder="请选择时间" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="出厂编号">
            <el-input v-model.trim="form.chuchangbh" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="生产厂家">
            <el-input v-model.trim="form.shengchancj" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="质量状况">
            <el-input v-model.trim="form.zhiliangzk" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="设施设备状态">
            <el-input v-model.trim="form.sssbzt" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="技术状况">
            <el-input v-model.trim="form.jishuzk" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="接装时间">
            <el-date-picker v-model.trim="form.jiezhuangsj" size="small" type="datetime"
              value-format="yyyy-MM-dd HH:mm:ss" :editable="false" placeholder="请选择时间" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="安装地点">
            <el-input v-model.trim="form.anzhaungdd" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="累计使用次数">
            <el-input v-model.trim="form.leijisycs" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="累计使用小时">
            <el-input v-model.trim="form.leijisyxs" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="累计公里数">
            <el-input v-model.trim="form.leijigls" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="大修次数">
            <el-input v-model.trim="form.daxiucs" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="中修次数">
            <el-input v-model.trim="form.zhongxiucs" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="随机工具配件">
            <el-input v-model.trim="form.sjgjpj" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="使用技术文件">
            <el-input v-model.trim="form.syjswj" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="单装价格">
            <el-input v-model.trim="form.danzhaungjg" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="登记人">
            <el-input v-model.trim="form.dengjir" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="登记时间">
            <el-date-picker v-model.trim="form.dengjisj" size="small" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
              :editable="false" placeholder="请选择时间" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="设备技术参数">
            <el-input v-model.trim="form.shebeijscs" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="是否列装">
            <el-input v-model.trim="form.zhongxiucs" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="配套情况">
            <el-input v-model.trim="form.peitaoqk" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="存放地方">
            <el-input v-model.trim="form.cunfangdd" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="质量等级">
            <el-input v-model.trim="form.zhiliangdj" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="备注">
            <el-input v-model.trim="form.beizhu" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="设备使用维修记录">
            <el-input v-model.trim="form.sbsywxjl" type="textarea" rows="5" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { doEdit } from '@/api/userManagement'

export default {
  name: 'UserManagementEdit',
  data() {
    return {
      form: {
        username: '',
        password: '',
        email: '',
        permissions: [],
      },
      rules: {
        username: [
          { required: true, trigger: 'blur', message: '请输入用户名' },
        ],
        password: [{ required: true, trigger: 'blur', message: '请输入密码' }],
        email: [{ required: true, trigger: 'blur', message: '请输入邮箱' }],
        permissions: [
          { required: true, trigger: 'blur', message: '请选择权限' },
        ],
      },
      title: '',
      dialogFormVisible: false,
      KufangList: []
    }
  },
  created() { },
  async mounted() {
    //库房
    // const kfData = await this.$util.getYHKf();
    // this.KufangList = kfData
    // console.log(kfData);
  },
  methods: {
    showEdit(row) {
      if (!row) {
        this.title = '新增'
      } else {
        this.title = '编辑'
        this.form = Object.assign({}, row)
      }
      this.dialogFormVisible = true
    },
    close() {
      this.$refs['form'].resetFields()
      this.form = this.$options.data().form
      this.dialogFormVisible = false
    },
    save() {
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          const { msg } = await doEdit(this.form)
          this.$baseMessage(msg, 'success')
          this.$emit('fetch-data')
          this.close()
        } else {
          return false
        }
      })
    },
  },
}
</script>
<style lang="scss" scoped>
::v-deep {
  .el-select {
    width: 100%;
  }

  .el-form-item__label {
    line-height: 16px !important;
  }

  .el-date-editor.el-input {
    width: 100%;
  }
}
</style>
